###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
#                           that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : PopulateSystemTab
#
# Description : Populate the System Tab when it is displayed
#
# Arguments :
#       w - Window name of system tab
#
# Returns :     Nothing
#
# Side-Effects :        None
#
# Exception Conditions :        None
#
# Pre-requisite Conditions :    None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
#                       update this segment of the file header block by
#                       adding a complete entry at the bottom of the list.
#
# Version     Date     Programmer   Comments / Changes / Reasons
# -------  ----------  ----------   -------------------------------------------
#       1  12/21/2009  G.Lester     Initial version
###########################################################################
proc PopulateSystemTab {w} {

    ##
    ## Get the data from FreshBooks
    ##
    set result [::WS::Client::DoRestCall FreshBookApi system system.current {}]

    ##
    ## Delete whatever was displayed
    ##
    $w.tree delete {}

    ##
    ## Set our unique ID counter to 0, IDs will be of the form node_XXX
    ##
    set node 0

    ##
    ## Insert the top level data
    ##
    $w.tree insert {} end \
        -id node_[incr node] \
        -text [::msgcat::mc Main.Tab.System.company_name.Title] \
        -values [list company_name [dict get $result company_name {}]]
    $w.tree insert {} end \
        -id node_[incr node] \
        -text [::msgcat::mc Main.Tab.System.profession.Title] \
        -values [list profession [dict get $result profession {}]]
    set addressNode node_[incr node]
    set apiNode node_[incr node]
    $w.tree insert {} end \
        -id $addressNode \
        -text [::msgcat::mc Main.Tab.System.address.Title] \
        -values [list address {}]
    $w.tree insert {} end \
        -id $apiNode \
        -text [::msgcat::mc Main.Tab.System.api.Title] \
        -values [list api {}]

    ##
    ## Insert address data as child of address node
    ##
    foreach child {street1 street2 city province postal_code country} {
        $w.tree insert $addressNode end \
            -id node_[incr node] \
            -text [::msgcat::mc Main.Tab.System.$child.Title] \
            -values [list $child [dict get $result address {} $child {}]]
    }


    ##
    ## Insert API data as child of API node
    ##
    foreach child {requests request_limit} {
        $w.tree insert $apiNode end \
            -id node_[incr node] \
            -text [::msgcat::mc Main.Tab.System.$child.Title] \
            -values [list $child [dict get $result api {} $child {}]]
    }

}
